<%--
  Created by IntelliJ IDEA.
  User: YLTDMenglc
  Date: 2019/11/29
  Time: 14:16
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
  <head>
    <title>$Title$</title>
  </head>
  <body>
  $END$hello
  </body>
</html>
<script>
    function arrSlice(arr) {
        if(arr.length % 2 !== 0) return 0;
        var newArr = [],tmpArr = []; //临时辅助数组
        for(var i=0;i<arr.length;i++) {
            if(!tmpArr.includes(arr[i])) {
                var rndIndex;
                do {
                    rndIndex = Math.floor(Math.random() * (arr.length - (i + 1))) + (i + 1);
                } while(tmpArr.includes(arr[rndIndex]));
                newArr.push([arr[i],arr[rndIndex]]);
                tmpArr.push(arr[i]);
                tmpArr.push(arr[rndIndex]);
            }
        }
        return newArr;
    }
    var arr = [1,2,3,4,5,6,7,8]
    console.log(arrSlice(arr));
</script>
